/**
 * Created by zhu on 2016/1/30.
 */
$(function(){
    $("#city-picker").on("click",function(){
        window.location.href=contextPath+"/my/add_address";
    });


    $.get(contextPath+"/fans/address",function(data){
        loadAddress(data);
    });
});

function loadAddress(data){
    data = jQuery.parseJSON(data);
    $('#myaddress').empty();
    $.each(data.list,function(i,item){
        var temp = '    <div class = "div_line"></div>'+
            '<div class="infoOfConsignee">'+
        '<div class="col01-5 colfloat">'+
        '<span class="icon "> </span>'+
        '</div>'+
        '<div class="col03-80 colfloat">'+
        '<div class = "inner_info info_01">'+
        '<div class = "inner_detail_left">'+item.fansName+'</div>'+
        '<div class = "inner_detail_right">'+item.phone+'</div>'+
        '</div>'+
        '<div class = "inner_info info_02">';
        if(item.flag == true){
            temp+='<span style="color: red">[默认] </span>';
        }else{
            temp+='<a style="color: black" onclick="setStatus('+item.id+')">[设为默认] </a>';
        }
        temp+=item.fansAddress+'</div>'+
        '</div>'+
        '<div class="col02-15 colfloat">'+
        '<span class="icon icon-right"></span>'+
        '</div>'+
        '</div>';
        $('#myaddress').append(temp);
    });


}

function setStatus(id){
    $.get(contextPath+"/fans/address/status/"+id,function(data){
        $.get(contextPath+"/fans/address",function(data){
            loadAddress(data);
        });
    });
}